package com.shopnight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shopnight.entity.TakeoutMerchant;
import com.shopnight.service.TakeoutMerchantService;
import com.shopnight.mapper.TakeoutMerchantMapper;
import com.shopnight.vo.MerchantListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author 13201
* @description 针对表【takeout_merchant(商户信息表)】的数据库操作Service实现
* @createDate 2023-03-08 15:14:02
*/
@Service
public class TakeoutMerchantServiceImpl extends ServiceImpl<TakeoutMerchantMapper, TakeoutMerchant>
    implements TakeoutMerchantService{
    @Autowired
    TakeoutMerchantMapper takeoutMerchantMapper;

    @Override
    public List<MerchantListVo> getTakeoutMerchantList(Integer orgId) {
        List<TakeoutMerchant> takeoutMerchants = takeoutMerchantMapper.selectList(
                //过滤符合条件的商家
                new LambdaQueryWrapper<TakeoutMerchant>()
                        .eq(TakeoutMerchant::getOrgId,orgId)
                        .eq(TakeoutMerchant::getState,1)
                        .eq(TakeoutMerchant::getIsValid,1)
        );

        List<MerchantListVo> merchantListVoList = takeoutMerchants.stream().map(TakeoutMerchant -> {
                    MerchantListVo merchantListVo = new MerchantListVo();
                    BeanUtils.copyProperties(TakeoutMerchant, merchantListVo);
                    merchantListVo.setMonthlySales(1000);
                    merchantListVo.setSpendTime(42);
                    merchantListVo.setPerCapitaPrice(19);
                    return merchantListVo;
                }
        ).collect(Collectors.toList());

        return merchantListVoList;
    }

    @Override
    public TakeoutMerchant getTakeoutMerchant(Integer id) {
        LambdaQueryWrapper<TakeoutMerchant> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TakeoutMerchant::getId,id)
                    .eq(TakeoutMerchant::getState,1)
                    .eq(TakeoutMerchant::getIsValid,1);
        TakeoutMerchant takeoutMerchant = takeoutMerchantMapper.selectOne(queryWrapper);
        return takeoutMerchant;
    }
}




